<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" :inline="true" label-width="140px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="单日获取积分数" prop="userId">
            <el-input
              v-model="queryParams.userName"
              placeholder="姓名"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="总积分" prop="possess">
            <el-input
              v-model="queryParams.possess"
              placeholder="请输入总积分"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="积分次数（单日）" prop="nums">
            <el-input
              v-model="queryParams.nums"
              placeholder="请输入单日获取积分次数"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="积分数（单日）" prop="count">
            <el-input
              v-model="queryParams.count"
              placeholder="请输入单日获取积分数"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['Integral:alarms:export']"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>

    <el-table v-loading="loading" :data="alarmsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="userName" />
      <el-table-column label="总积分" align="center" prop="possess" />
      <el-table-column label="单日获取积分次数" align="center" prop="nums" />
      <el-table-column label="单日获取积分数" align="center" prop="count" />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            type="text"
            icon="el-icon-s-order"
            @click="showPersonDetail(scope.row)"
          >明细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listAlarms, exportAlarms } from '@/api/integral/alarms'

export default {
  name: 'Alarms',
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报警信息表表格数据
      alarmsList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        communityId: null,
        possess: null,
        nums: null,
        count: null,
        userName: null
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询报警信息表列表 */
    getList() {
      this.loading = true
      listAlarms(this.queryParams).then(response => {
        this.alarmsList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$confirm('是否确认导出所有报警信息表数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return exportAlarms(queryParams)
      }).then(response => {
        this.download(response.msg)
      })
    },
    // 跳转到明细
    showPersonDetail(person) {
      person.nickName = person.userName
      this.$router.push({
        path: 'integraldetail',
        query: {
          person
        }
      })
    }
  }
}
</script>
